<!-- HTML header for doxygen 1.9.1-->
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=9" />
    <meta name="generator" content="Doxygen 1.9.4" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>NumCpp: InterfaceWithEigen.cpp</title>
    <link href="tabs.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="dynsections.js"></script>
    <link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
    <link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
    <link href="doxygen.css" rel="stylesheet" type="text/css" />
    <link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
<link href="doxygen-awesome-sidebar-only-darkmode-toggle.css" rel="stylesheet" type="text/css"/>
    <!-- ... other metadata & script includes ... -->
    <script type="text/javascript" src="../doxygen-awesome-css/doxygen-awesome-darkmode-toggle.js"></script>
    <script type="text/javascript">
        DoxygenAwesomeDarkModeToggle.init()
    </script>
    <script type="text/javascript"
        src="../doxygen-awesome-css/doxygen-awesome-fragment-copy-button.js"></script>
    <script type="text/javascript">
        DoxygenAwesomeFragmentCopyButton.init()
    </script>
    <script type="text/javascript" src="../doxygen-awesome-css/doxygen-awesome-paragraph-link.js"></script>
    <script type="text/javascript">
        DoxygenAwesomeParagraphLink.init()
    </script>
    <script type="text/javascript" src="../doxygen-awesome-css/doxygen-awesome-interactive-toc.js"></script>
    <script type="text/javascript">
        DoxygenAwesomeInteractiveToc.init()
    </script>
</head>
<body>
    <div id="top">
        <!-- do not remove this div, it is closed by doxygen! -->
        <div id="titlearea">
            <table cellspacing="0" cellpadding="0">
                <tbody>
                    <tr style="height: 56px;">
                        <td id="projectlogo"><img alt="Logo" src="NumCppLogoDoxygen.png" /></td>
                        <td id="projectalign" style="padding-left: 0.5em;">
                            <div id="projectname">NumCpp
                                &#160;<span id="projectnumber">2.12.1</span>
                            </div>
                            <div id="projectbrief">A Templatized Header Only C++ Implementation of the Python NumPy Library</div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <!-- end header part --><!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('_interface_with_eigen_8cpp-example.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle"><div class="title">InterfaceWithEigen.cpp</div></div>
</div><!--header-->
<div class="contents">
<p >Example for interfaceing with Eigen Matrix</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="_num_cpp_8hpp.html">NumCpp.hpp</a>&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &lt;Eigen/Dense&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;vector&gt;</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">using </span>EigenIntMatrix    = Eigen::Matrix&lt;int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor&gt;;</div>
<div class="line"><span class="keyword">using </span>EigenIntMatrixMap = Eigen::Map&lt;EigenIntMatrix&gt;;</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line">    <span class="comment">// construct some NumCpp arrays</span></div>
<div class="line">    <span class="keyword">auto</span> ncA = nc::random::randInt&lt;int&gt;({ 5, 5 }, 0, 10);</div>
<div class="line">    <span class="keyword">auto</span> ncB = nc::random::randInt&lt;int&gt;({ 5, 5 }, 0, 10);</div>
<div class="line"> </div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;ncA:\n&quot;</span> &lt;&lt; ncA &lt;&lt; std::endl;</div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;ncB:\n&quot;</span> &lt;&lt; ncB &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// map the arrays to Eigen</span></div>
<div class="line">    <span class="keyword">auto</span> eigenA = EigenIntMatrixMap(ncA.data(), ncA.numRows(), ncA.numCols());</div>
<div class="line">    <span class="keyword">auto</span> eigenB = EigenIntMatrixMap(ncB.data(), ncB.numRows(), ncB.numCols());</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// add the two Eigen matrices</span></div>
<div class="line">    <span class="keyword">auto</span> eigenC = eigenA + eigenB;</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// add the two NumCpp arrays for a sanity check</span></div>
<div class="line">    <span class="keyword">auto</span> ncC = ncA + ncB;</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// convert the Eigen result back to NumCpp</span></div>
<div class="line">    <span class="keyword">auto</span> data                                                    = std::vector&lt;int&gt;(eigenC.rows() * eigenC.cols());</div>
<div class="line">    EigenIntMatrixMap(data.data(), eigenC.rows(), eigenC.cols()) = eigenC;</div>
<div class="line"> </div>
<div class="line">    <span class="keyword">auto</span> ncCeigen = <a id="_a0" name="_a0"></a><a class="code hl_class" href="classnc_1_1_nd_array.html">nc::NdArray&lt;int&gt;</a>(data.data(), eigenC.rows(), eigenC.cols(), <a id="a1" name="a1"></a><a class="code hl_enumvalue" href="namespacenc.html#ae31148c2c120e8ed49df98e7dcd960eca28d568b3892dce36f2833542693a1062">nc::PointerPolicy::SHELL</a>);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// compare the two outputs</span></div>
<div class="line">    <span class="keywordflow">if</span> (<a id="a2" name="a2"></a><a class="code hl_function" href="namespacenc.html#a0e8c1396cc01ccd9ec8ba549b6347e21">nc::array_equal</a>(ncC, ncCeigen))</div>
<div class="line">    {</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;Arrays are equal.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line">        std::cout &lt;&lt; ncC &lt;&lt; std::endl;</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">else</span></div>
<div class="line">    {</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;Arrays are not equal.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;ncCeigen:\n&quot;</span> &lt;&lt; ncCeigen &lt;&lt; std::endl;</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;ncC:\n&quot;</span> &lt;&lt; ncC &lt;&lt; std::endl;</div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="ttc" id="a_num_cpp_8hpp_html"><div class="ttname"><a href="_num_cpp_8hpp.html">NumCpp.hpp</a></div></div>
<div class="ttc" id="aclassnc_1_1_nd_array_html"><div class="ttname"><a href="classnc_1_1_nd_array.html">nc::NdArray</a></div><div class="ttdoc">Holds 1D and 2D arrays, the main work horse of the NumCpp library.</div><div class="ttdef"><b>Definition:</b> NdArrayCore.hpp:139</div></div>
<div class="ttc" id="anamespacenc_html_a0e8c1396cc01ccd9ec8ba549b6347e21"><div class="ttname"><a href="namespacenc.html#a0e8c1396cc01ccd9ec8ba549b6347e21">nc::array_equal</a></div><div class="ttdeci">bool array_equal(const NdArray&lt; dtype &gt; &amp;inArray1, const NdArray&lt; dtype &gt; &amp;inArray2) noexcept</div><div class="ttdef"><b>Definition:</b> array_equal.hpp:47</div></div>
<div class="ttc" id="anamespacenc_html_ae31148c2c120e8ed49df98e7dcd960eca28d568b3892dce36f2833542693a1062"><div class="ttname"><a href="namespacenc.html#ae31148c2c120e8ed49df98e7dcd960eca28d568b3892dce36f2833542693a1062">nc::PointerPolicy::SHELL</a></div><div class="ttdeci">@ SHELL</div></div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
  </ul>
</div>
</body>
</html>
